package com.briup.service.Impl;

import com.briup.bean.Category;
import com.briup.bean.vo.CategoryVO;
import com.briup.dao.ICategoryDao;
import com.briup.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ICategoryServiceImpl implements ICategoryService {
    @Autowired
    private ICategoryDao categoryDao;

    @Override
    public List<CategoryVO> findAllCategory() {
        List<Category> list = categoryDao.findByParentIdIsNull();
        List<CategoryVO> cv = new ArrayList<>();
        list.forEach(x->{
            List<Category> second = categoryDao.findByParentId(x.getId());
            cv.add(new CategoryVO(x,second));
        });
        return cv;
    }
}
